package com.ccxc.question.exam.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ccxc.question.exam.dto.OperationDTO;
import com.ccxc.question.exam.service.AnswerService;
import com.ccxc.question.exam.service.InformationService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping("/v1/open/operation/manager")
@Api("答题操作相关API")
@Slf4j
public class AnswerController {

    @Autowired
    private AnswerService answerService;
    @Autowired
    private InformationService informationService;

    @PutMapping(value = "/submit", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(httpMethod = "PUT", value = "提交答案", notes = "提交答案<br><br><b>@author 郑尚锟</b>")
    public String contrast(
            @ApiParam(value = "用户ID", required = true) @RequestParam(required = true, value = "userid") String userid,
            @ApiParam(value = "题目ID", required = true) @RequestParam(required = true, value = "queid") String queid,
            @ApiParam(value = "题目答案", required = true) @RequestParam(required = true, value = "answer") String answer
    ) {
        OperationDTO operationDto = new OperationDTO();
        if (informationService.judgeuserid(userid)) {
        operationDto.setUserid(userid);
        operationDto.setQueid(queid);
        operationDto.setAnswer(answer);
        log.debug("答题结果：{}", operationDto);
        return answerService.contrast(operationDto);
        }
        else {
			return "该用户不存在！！！";  
		}
    }


}
